var setting = {
		data: {  
            simpleData: {  
                enable: true  
            }  
        } ,
		async: {
			enable: true,
			url:"classifySynTree.do",
			autoParam:["id", "name", "level"],
			otherParam:{"parentId":"0"},
			dataFilter: filter
		},
		callback: {
			onClick: zTreeOnClick
		}
		
	};

function zTreeOnClick(event, treeId, treeNode) {
	$("#classId").val(treeNode.id);
	$("#className").val(treeNode.name);
	$("#tbody").html('');
	$.ajax({
		url:'brandSynByclassifyId.do',
		type:'post',
		data:{'classifyid': treeNode.id},
		dataType:'json',
		success:function(data){
			var tr = '';
			for(var i=0; i<data.length; i++) {
				 tr = tr + '<tr><td><input type="radio" id = "brandid" name = "brandid" value = ' + data[i].brandid +' brandname =  ' + data[i].brandname + '></td><td>' + data[i].brandname + '</td></tr>';
			}
			$("#tbody").html(tr);
			radioChange();
		}	
	});
   /* alert(treeNode.tId + ", " + treeNode.name);*/
};

var radioChange = function () {
	$(":radio").on("change",function(){
		$("#brandId").val($(this).val());
		$("#brandName").val($(this).attr('brandname'));
	})
}

	function filter(treeId, parentNode, childNodes) {
		if (!childNodes) return null;
		for (var i=0, l=childNodes.length; i<l; i++) {
			childNodes[i].id = childNodes[i].id;
			childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
			//console.log(childNodes[i].id);
			if(childNodes[i].isParent > 0) {
				childNodes[i].isParent = true;
			}else{
				childNodes[i].isParent = false;
			}
			
		}
		return childNodes;
	}

	$(document).ready(function(){
		$.fn.zTree.init($("#treeDemo"), setting);
});